import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { findSubCategoryFilter } from '@/api/category'
export function setLoadData () {
  const subCategoryData = ref({})
  const route = useRoute()
  async function loadSubData () {
    const res = await findSubCategoryFilter(route.params.id)
    subCategoryData.value = res.result
    subCategoryData.value.brands.unshift({
      id: null,
      name: '全部',
      selected: true
    })
    subCategoryData.value.saleProperties.forEach((itm) => {
      itm.properties.forEach((obj) => {
        obj.selected = false
      })
      itm.properties.unshift({
        id: null,
        name: '全部',
        selected: true
      })
    })
  }
  onMounted(() => {
    loadSubData()
  })
  return {
    subCategoryData
  }
}
